<?php
namespace Topxia\WebBundle\Util;

use Topxia\Service\Common\ServiceKernel;

class CategoryBuilder
{
	public function buildChoices($groupCode, $indent = '　')
	{
        $group = $this->getCategoryService()->getGroupByCode($groupCode);
        if (empty($group)) {
        	return array();
        }

        $choices = array();
        //$categories = $this->getCategoryService()->getCategoryTree($group['id']);
		//bread加入2014年11月20日 21:39:42
        $allgroups = $this->getCategoryService()->findAllGroups();
        $color = array(
        			'1'=>'color:red',
        			'2'=>'color:cadetblue',
        			'3'=>'color:seagreen',
        			'4'=>'color:#39b3d7',
        			'5'=>'color:#428bca',
        			);
        if($allgroups){
        	$categories = $groups_rs = array();
        	foreach ( $allgroups as $key => $value ) {
        		$data = $this->getCategoryService()->getCategoryTree($value['id']);
        		$categories = array_merge($categories, $data);
        	}
        }
        ///////
        
        
        foreach ($categories as $category) {
            $choices[$category['id']] = str_repeat(is_null($indent) ? '' : $indent, ($category['depth']-1)) . $category['name'];
        }
        return $choices;
	}

    private function getCategoryService()
    {
        return ServiceKernel::instance()->createService('Taxonomy.CategoryService');
    }
}
    